<template>
	<div class="content">
		<Login v-if="!isLogin"></Login>
		<Modal v-model="modal11">
			<img :src="url"/>
		</Modal>
		<div id="total" v-if="isLogin">
			<div class="width1190">
				<h2 class="title">卖房 <router-link to="/fang_sale">更多&gt;&gt;</router-link>
				</h2>
				<div class="index-fang-list">
					<div v-for="(item, index) in houseSaleArray" @click="detailHouseSell(item.sellId)">
						<houseSale  v-bind:house="item"></houseSale>
					</div>
					
					<div class="clears"></div>
				</div>
				
				<!--index-fang-list/  @click.native="cc()"-->
				<h2 class="title">求购房 <router-link :to="'/fang_buy'" >更多&gt;&gt;</router-link>
				</h2>
				<div class="pg-ground">
					<div style="display: inline-block;cursor: pointer;" v-for="(item, index) in houseBuyArray" @click="detailHouseBuy(item.houseBuyId)">
					<houseBuy  v-bind:info="item"></houseBuy>
					</div>
					<div class="clears"></div>
				</div>
				<h2 class="title">租房 <router-link to="/fang_zu">更多&gt;&gt;</router-link>
				</h2>
				<div class="index-fang-list">
					<div v-for="(item, index) in houseZuArray"  @click="detailHouseLease(item.leaseId)">
						<houseZu v-bind:house="item" ></houseZu>
						</div>
					<div class="clears"></div>
				</div>
				<!--index-fang-list/-->
				<h2 class="title">求租房 <router-link to="/fang_qiuzu">更多&gt;&gt;</router-link>
				</h2>
				<div class="pg-ground">
					<div style="display: inline-block;cursor: pointer;" v-for="(item, index) in houseQiuzuArray" @click="detailHouseRent(item.houseRentId)">
					<houseQiuZu  v-bind:info="item"></houseQiuZu>
					</div>
					<div class="clears"></div>
				</div>
				<!--index-fang-list/-->
			
			</div>
			<!--width1190/-->
			
			<div class="width1190">
				<h2 class="title">卖车 <a href="#" @click.prevent="carlist()">更多&gt;&gt;</a></h2>
				<div class="index-fang-list" >
					<div v-for="(item, index) in carSaleArray" @click="carDetail(item.carSellInfoId,item.carId)">
						<carSale v-bind:car="item"></carSale>
					</div>
					<div class="clears"></div>
				</div>
				<!--index-fang-list/-->
				<h2 class="title">求购车 <a href="#" @click.prevent="qiuBuy()">更多&gt;&gt;</a></h2>
				<div class="pg-ground">
					<div style="display: inline-block;cursor: pointer;" v-for="(item, index) in carBuyArray" @click="carBuyDetail(item.cbId)">
						<carBuy  v-bind:info="item"></carBuy>
					</div>
					<div class="clears"></div>
				</div>
				<h2 class="title">租车 <router-link to="/car_zu">更多&gt;&gt;</router-link>
				</h2>
				<div class="index-fang-list">
					<div v-for="(item, index) in carZuArray" @click="carZuDetail(item.carId)">
						<carZu v-bind:car="item"></carZu>
					</div>
					<div class="clears"></div>
				</div>
				<!--index-fang-list/-->
				<h2 class="title">求租车 <router-link to="/car_qiuzu">更多&gt;&gt;</router-link>
				</h2>
				<div class="pg-ground">
					<div style="display: inline-block;cursor: pointer;" v-for="(item, index) in carQiuzuArray" @click="carQiu(item.crId)">
						<carQiuZu v-bind:info="item"></carQiuZu>
					</div>
					<div class="clears"></div>
				</div>
			
			</div>
		</div>
		
		<!--width1190/-->
        <router-view></router-view>
	</div>
</template>

<script>
	import store from '../../common/store.js';
	import Login from '../components/login.vue';
	import Vue from 'vue';
	import houseSale from "../components/house.vue";
	import houseBuy from "../components/qiu.vue";
	import houseZu from "../components/house.vue";
	import houseQiuZu from "../components/qiu.vue";
	import carSale from "../components/car.vue";
	import carBuy from "../components/qiu.vue";
	import carZu from "../components/car.vue";
	import carQiuZu from "../components/qiu.vue";


	export default {
		components: {
			houseSale,
			houseBuy,
			houseZu,
			houseQiuZu,
			carSale,
			carBuy,
			carZu,
			carQiuZu,
			Login
		},
		data: function() {
			return {
        iport: '',
				time : "",
				url : "",
				modal11 : false,
				clientId : 0, 
				orderInfo : {},
				houseBuyArray: [

				],
				houseSaleArray: [

				],
				houseQiuzuArray: [

				],
				houseZuArray: [

				],
				carBuyArray: [

				],
				carSaleArray: [

				],
				carQiuzuArray: [

				],
				carZuArray: [

				],
			};
		},
		methods: {
			wx(orderTypeId){
				clearInterval(this.time)
				let self = this
				this.$data.modal11 = true
				var om = self.$data.orderInfo.orderNumber
				var i = 10;
				this.time = setInterval(function(){
					console.log(i);
					self.http.get({
						url:'/pay-order/info',
						param:{
							orderNumber : om
						}
					}).then((data) => {
						if(data == 2){
							clearInterval(self.$data.time)
							self.$Notice.success({
							  title: '支付成功',
							});
							self.$data.modal11 = false
						}
						})
					i = i -1
					if(i==0){
						clearInterval(self.$data.time)
						self.$data.modal11 = false
						self.$Notice.error({
						  title: '支付超时',
						});
					}
				},3000)
			},
			carQiu(crId){
				this.clientId = JSON.parse(sessionStorage.getItem('CURRENT')).client.clientId;
				console.log(this.clientId);
				this.http.get({
					url: "/quotarecord/info",
					param: {
						clientId: this.clientId,
						orderTypeId : 16
					}
				}).then(data => {
					if(data.quota +1 > 0){
						this.$router.push({
							name:'car_qiuzu_detail',
							params:{
								crId
							}
						})
					} else{
						let paramm = {};
						let self = this
						this.http.post({
							url:'/pay-order/info',
							param:{
								clientId:this.clientId,
								orderTypeId:16
							}
						}).then((data) => {
							self.$data.orderInfo = data
							paramm.clientId = this.$data.orderInfo.clientId;
							paramm.orderNumber = this.$data.orderInfo.orderNumber;
							paramm.price = this.$data.orderInfo.price;
							paramm.orderTypeId = this.$data.orderInfo.orderTypeId;
							this.modal11 = true;
							this.url = this.iport + 'pay/nativeV2?clientId='+paramm.clientId
							+'&orderTypeId='+paramm.orderTypeId
							+'&money='+paramm.price
							+'&orderNumber='+paramm.orderNumber
							this.wx()
							})
							console.log(paramm)
					}
					console.log(data);
					});
			},
			carZuDetail(carId){
				this.clientId = JSON.parse(sessionStorage.getItem('CURRENT')).client.clientId;
				console.log(this.clientId);
				this.http.get({
					url: "/quotarecord/info",
					param: {
						clientId: this.clientId,
						orderTypeId : 14
					}
				}).then(data => {
					if(data.quota +1 > 0){
						this.$router.push({
							name:'car_zu_detail',
							params:{
								carId
							}
						})
					} else{
						let paramm = {};
						this.http.post({
							url:'/pay-order/info',
							param:{
								clientId:this.clientId,
								orderTypeId:14
							}
						}).then((data) => {
							this.$data.orderInfo = data
							paramm.clientId = this.$data.orderInfo.clientId;
							paramm.orderNumber = this.$data.orderInfo.orderNumber;
							paramm.price = this.$data.orderInfo.price;
							paramm.orderTypeId = this.$data.orderInfo.orderTypeId;
							this.modal11 = true;
							this.url =  this.iport + 'pay/nativeV2?clientId='+paramm.clientId
							+'&orderTypeId='+paramm.orderTypeId
							+'&money='+paramm.price
							+'&orderNumber='+paramm.orderNumber
							this.wx()
							})
					}
					console.log(data);
					});
			},
			carBuyDetail(cbId){
				this.clientId = JSON.parse(sessionStorage.getItem('CURRENT')).client.clientId;
				console.log(this.clientId);
				this.http.get({
					url: "/quotarecord/info",
					param: {
						clientId: this.clientId,
						orderTypeId : 15
					}
				}).then(data => {
					if(data.quota +1 > 0){
						this.$router.push({
							name:'car_buy_detail',
							params:{
								cbId
							}
						})
					} else{
						let paramm = {};
						this.http.post({
							url:'/pay-order/info',
							param:{
								clientId:this.clientId,
								orderTypeId:15
							}
						}).then((data) => {
							this.$data.orderInfo = data
							paramm.clientId = this.$data.orderInfo.clientId;
							paramm.orderNumber = this.$data.orderInfo.orderNumber;
							paramm.price = this.$data.orderInfo.price;
							paramm.orderTypeId = this.$data.orderInfo.orderTypeId;
							this.modal11 = true;
							this.url = this.iport + 'pay/nativeV2?clientId='+paramm.clientId
							+'&orderTypeId='+paramm.orderTypeId
							+'&money='+paramm.price
							+'&orderNumber='+paramm.orderNumber
							this.wx()
							})
					}
					console.log(data);
					});
			},
			//卖车详情
      carDetail(carSellInfoId,carId){
				this.clientId = JSON.parse(sessionStorage.getItem('CURRENT')).client.clientId;
				console.log(this.clientId);
				this.http.get({
					url: "/quotarecord/info",
					param: {
						clientId: this.clientId,
						orderTypeId : 13
					}
				}).then(data => {
					if(data.quota +1 > 0){
						this.$router.push({
							name:'car_sale_detail',
							params:{
								carSellInfoId,
								carId
							}
						})
					} else{
						let paramm = {};
						this.http.post({
							url:'/pay-order/info',
							param:{
								clientId:this.clientId,
								orderTypeId:13
							}
						}).then((data) => {
							this.$data.orderInfo = data
							paramm.clientId = this.$data.orderInfo.clientId;
							paramm.orderNumber = this.$data.orderInfo.orderNumber;
							paramm.price = this.$data.orderInfo.price;
							paramm.orderTypeId = this.$data.orderInfo.orderTypeId;
							this.modal11 = true;
							this.url = this.iport + 'pay/nativeV2?clientId='+paramm.clientId
							+'&orderTypeId='+paramm.orderTypeId
							+'&money='+paramm.price
							+'&orderNumber='+paramm.orderNumber
							this.wx()
							})
					}
					console.log(data);
					});
			},
			// 卖房
			houseSell: function() {
				this.http.get({
					url: "/house-sell-client-vo/page",
					param: {
						currentPage: 1,
						pageSize: 4
					}
				}).then(data => {
					let self = this;
					for (let index in data.records) {
						let item = data.records[index];
						item.sellPrice = item.totalPrice;
						self.$data.house = item;
					}
					self.$data.houseSaleArray = data.records;
				});
			},
			// 买房
			houseBuy: function() {
				this.http.get({
					url: "/house-buy-client-vo/page",
					param: {
						currentPage: 1,
						pageSize: 5
					}
				}).then(data => {
					console.log(data)
					let self = this;
					for (let index in data.records) {
						let item = data.records[index];
						item.sellPrice = item.totalPrice;
						item.details = item.detail;
						self.$data.house = item;
					}
					self.$data.houseBuyArray = data.records;
				});
			},
			// 租房
			houseLease: function() {
				this.http.get({
					url: "/house-lease-client-vo/page",
					param: {
						currentPage: 1,
						pageSize: 4
					}
				}).then(data => {
					
					let self = this;
					for (let index in data.records) {
						let item = data.records[index];
						item.sellPrice = item.leasePrice;
						self.$data.house = item;
					}
					self.$data.houseZuArray = data.records;
				});
			},
			// 求租房
			houseRent: function() {
				this.http.get({
					url: "/house-rent-client-vo/page",
					param: {
						currentPage: 1,
						pageSize: 5
					}
				}).then(data => {
					let self = this;
					for (let index in data.records) {
						let item = data.records[index];
						item.sellPrice = item.totalPrice;
						item.details = item.detail;
						self.$data.house = item;
					}
					self.$data.houseQiuzuArray = data.records;
				});
			},
			//租车
			carRental: function() {
				let self = this;
				self.http.get({
					url: "/car-rental-info/page",
					param: {
						currentPage: 1,
						pageSize: 4
					}
				}).then(data => {
					for (let index in data.records) {
						let item = data.records[index];
						item.price = item.rentalPrice;
					}
					self.$data.carZuArray = data.records;
				});
			},
			//求租车
			carRent: function() {
				let self = this;
				self.http.get({
					url: "/car-rent-info/page",
					param: {
						currentPage: 1,
						pageSize: 5
					}
				}).then(data => {
					for (let index in data.records) {
						let item = data.records[index];
						item.price = item.rentalPrice;
					}
					self.$data.carQiuzuArray = data.records;
				});
			},
			//卖车
			carSale: function() {
				let self = this;
				self.http.get({
					url: "/car-sell-info/page",
					param: {
						currentPage: 1,
						pageSize: 4
					}
				}).then(data => {
					for (let index in data.records) {
						let item = data.records[index];
						item.price = item.sellPrice;
						self.$data.car = item;
					}
					self.$data.carSaleArray = data.records;
				});
			},
			//买车
			carBuy: function() {
				let self = this;
				self.http.get({
					url: "/car-buy-vo/page",
					param: {
						currentPage: 1,
						pageSize: 5
					}
				}).then(data => {
					for (let index in data.records) {
						let item = data.records[index];
						self.$data.info = item;
					}
					self.$data.carBuyArray = data.records;
				});

			},
			// 租房详情
			detailHouseLease: function(leaseId) {
				this.clientId = JSON.parse(sessionStorage.getItem('CURRENT')).client.clientId;
				console.log(this.clientId);
				this.http.get({
					url: "/quotarecord/info",
					param: {
						clientId: this.clientId,
						orderTypeId : 10
					}
				}).then(data => {
					if(data.quota +1 > 0){
						this.$router.push({
							name:'house_zu_detail',
							params:{
								leaseId
							}
						})
					} else{
						let paramm = {};
						let self = this
						this.http.post({
							url:'/pay-order/info',
							param:{
								clientId:this.clientId,
								orderTypeId:10
							}
						}).then((data) => {
							self.$data.orderInfo = data
							console.log("orderInfo" + self.$data.orderInfo)
							console.log(self.$data.orderInfo)
							paramm.clientId = this.$data.orderInfo.clientId;
							paramm.orderNumber = this.$data.orderInfo.orderNumber;
							paramm.price = this.$data.orderInfo.price;
							paramm.orderTypeId = this.$data.orderInfo.orderTypeId;
							this.modal11 = true;
							this.url = this.iport + 'pay/nativeV2?clientId='+paramm.clientId
							+'&orderTypeId='+paramm.orderTypeId
							+'&money='+paramm.price
							+'&orderNumber='+paramm.orderNumber
							this.wx()
							})
					}
					
					console.log(data);
					});
			},
			// 求购房详情
			detailHouseBuy: function(houseBuyId) {
				
				this.clientId = JSON.parse(sessionStorage.getItem('CURRENT')).client.clientId;
				console.log(this.clientId);
				this.http.get({
					url: "/quotarecord/info",
					param: {
						clientId: this.clientId,
						orderTypeId : 12
					}
				}).then(data => {
					if(data.quota +1 > 0){
						this.$router.push({
							name:'house_buy_detail',
							params:{
								houseBuyId
							}
						})
					} else{
						let paramm = {};
						this.http.post({
							url:'/pay-order/info',
							param:{
								clientId:this.clientId,
								orderTypeId:12
							}
						}).then((data) => {
							this.$data.orderInfo = data
							paramm.clientId = this.$data.orderInfo.clientId;
							paramm.orderNumber = this.$data.orderInfo.orderNumber;
							paramm.price = this.$data.orderInfo.price;
							paramm.orderTypeId = this.$data.orderInfo.orderTypeId;
							this.modal11 = true;
							this.url = this.iport + 'pay/nativeV2?clientId='+paramm.clientId
							+'&orderTypeId='+paramm.orderTypeId
							+'&money='+paramm.price
							+'&orderNumber='+paramm.orderNumber
							this.wx()
							})
					}
					console.log(data);
					});
			},
			// 求租房详情
			detailHouseRent: function(houseRentId) {
				
				this.clientId = JSON.parse(sessionStorage.getItem('CURRENT')).client.clientId;
				console.log(this.clientId);
				this.http.get({
					url: "/quotarecord/info",
					param: {
						clientId: this.clientId,
						orderTypeId : 11
					}
				}).then(data => {
					if(data.quota +1 > 0){
						this.$router.push({
							// target:'blank',
							name:'house_qiuzu_detail',
							params:{
								houseRentId
							}
						})
					} else{
						let paramm = {};
						this.http.post({
							url:'/pay-order/info',
							param:{
								clientId:this.clientId,
								orderTypeId:11
							}
						}).then((data) => {
							this.$data.orderInfo = data
							paramm.clientId = this.$data.orderInfo.clientId;
							paramm.orderNumber = this.$data.orderInfo.orderNumber;
							paramm.price = this.$data.orderInfo.price;
							paramm.orderTypeId = this.$data.orderInfo.orderTypeId;
							this.modal11 = true;
							this.url = this.iport + 'pay/nativeV2?clientId='+paramm.clientId
							+'&orderTypeId='+paramm.orderTypeId
							+'&money='+paramm.price
							+'&orderNumber='+paramm.orderNumber
              console.log(this.url)
							this.wx()
							})
					}
					console.log(data);
					});
				
			},
			// 卖房房详情
			detailHouseSell: function(sellId) {	
				this.clientId = JSON.parse(sessionStorage.getItem('CURRENT')).client.clientId;
				console.log(this.clientId);
				
				this.http.get({
					url: "/quotarecord/info",
					param: {
						clientId: this.clientId,
						orderTypeId : 9
					}
				}).then(data => {
					if(data.quota +1 > 0){
						this.$router.push({
							name:'house_sale_detail',
							params:{
								sellId
							}
						})
					} else{
						let paramm = {};
						this.http.post({
							url:'/pay-order/info',
							param:{
								clientId:this.clientId,
								orderTypeId:9
							}
						}).then((data) => {
							this.$data.orderInfo = data
							paramm.clientId = this.$data.orderInfo.clientId;
							paramm.orderNumber = this.$data.orderInfo.orderNumber;
							paramm.price = this.$data.orderInfo.price;
							paramm.orderTypeId = this.$data.orderInfo.orderTypeId;
							this.modal11 = true;
							this.url = this.iport + 'pay/nativeV2?clientId='+paramm.clientId
							+'&orderTypeId='+paramm.orderTypeId
							+'&money='+paramm.price
							+'&orderNumber='+paramm.orderNumber
							this.wx()
							})
					}
					console.log(data);
					});
			},
			//卖车列表
						carlist(){
							this.$router.push({
								name:'car_sale'
							})
						},
						qiuBuy(){
										this.$router.push({
											name:'car_buy'
										})
									},
						
		},
		created: function() {
      this.iport = this.store.state.iport
			store.commit("checkLogin");
			this.carSale();
			this.carBuy();
			this.carRental();
			this.carRent();
			this.houseSell();
			this.houseBuy();
			this.houseLease();
			this.houseRent()
		},
		computed: {
			isLogin() {
				console.log(store.state.isAlreadyLogin);
				return store.state.isAlreadyLogin;
			}
		}
		// beforeRouteLeave(to, from, next) {
		//     this.$destroy();//手动销毁当前页面
		//     next();
		// },
	}
</script>

<style>
</style>
